package com.openness.crawler.zookeeper;

import java.util.concurrent.CountDownLatch;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.KeeperState;

/**
 * @author Rain
 * @version 2013-6-4 上午11:07:41
 */

public class ZKConnectionLatch implements Watcher {

	private CountDownLatch latch = new CountDownLatch(1);

	@Override
	public void process(WatchedEvent event) {
		if (event.getState() == KeeperState.SyncConnected) {
			latch.countDown();
		}

	}

	public void await() throws InterruptedException {
		latch.await();
	}

}
